package com.example;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Scanner;

public class DBUtil {
    public static void main(String[] args) throws SQLException {
        MysqlDataSource dataSource =  new MysqlDataSource();
        dataSource.setURL("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
        dataSource.setUser("root");
        dataSource.setPassword("284013");
        Connection connection =dataSource.getConnection();
        Scanner scanner = new Scanner(System.in);
        String sql = scanner.nextLine();

        PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql);

        int ret = statement.executeUpdate();
        System.out.println("sql: " + statement);//输出sql语句的信息
        System.out.println("ret = "+ret);
        statement.close();
        connection.close();
    }
}
